package com.jzoffer2;


import ds.TreeNode;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No28
 * @description
 * @date 2021/2/1 下午12:51
 */
public class No28 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        TreeNode t1 = new TreeNode(2);
        TreeNode t2 = new TreeNode(3);
        TreeNode t3 = new TreeNode(2);
        TreeNode t4 = new TreeNode(3);
        root.left = t1;
        t1.right = t2;
        root.right = t3;
        t3.left = t4;
        boolean res = isSymmetric(root);
        System.out.println(res);

    }

    public static boolean isSymmetric(TreeNode root) {
        if(root == null){
            return true;
        }
        return isSubSymmetric(root.left,root.right);

    }

    private static boolean isSubSymmetric(TreeNode left, TreeNode right) {
        if(left == null && right == null){
            return true;
        }
        if(left == null || right == null){
            return false;
        }
        if(left.val != right.val){
            return false;
        }
        return isSubSymmetric(left.left,right.right) && isSubSymmetric(left.right,right.left);
    }
}
